/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.erp.erp.security.logic;

import java.security.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * This class Contain MD5 Cipher To encrypt Texts, Originally It's written to
 * encrypt passwords
 *
 * @author maha
 */
public class Ciphers {

    public static String getEncryptedTextUsingMD5(String text) {
        byte[] textInBytes = text.getBytes();
        StringBuilder hexString = null;
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(textInBytes);
            byte[] messageDigestion = algorithm.digest();
            hexString = new StringBuilder();
            for (int i = 0; i < messageDigestion.length; i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigestion[i]));
            }

        } catch (NoSuchAlgorithmException ex) {
            System.out.println("Exception occured in getEncryptedTextUsingMD5 in class Ciphers");
            ex.printStackTrace();
        }
        return hexString.toString();
    }
}
